package com.chaos.payment.service.bsns;

import cn.hutool.core.bean.BeanUtil;
import com.chaos.framework.model.dto.result.data.DataResult;

import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;

import java.util.Objects;

/**
 * @description:
 * @author: crayon
 * @time: 2024/6/19 13:25
 */
@Component
@RequiredArgsConstructor
public class OrderPayBsns {

    //private final PayClient payClient;

//    private final UnifiedOrderService unifiedOrderService;
//
//    /**
//     * 订单支付
//     * 余额充值 - 订单流水 -余额流水
//     * 余额支付 - 订单流水 -余额流水
//     *
//     * @param orderPayDto
//     * @return
//     */
//    public DataResult<PayResponse> pay(OrderPayDto orderPayDto) {
//        Integer orderType = orderPayDto.getOrderType();
//        AbstractOrder orderHandler = unifiedOrderService.getOrderHandler(orderType);
//        //判断订单状态
//        UnifiedXsnOrderDto unixOrderDto = new UnifiedXsnOrderDto();
//        unixOrderDto.setOrderNo(orderPayDto.getOrderNo());
//        unixOrderDto.setOrderType(orderType);
//        BeanUtil.copyProperties(orderPayDto, unixOrderDto);
//        orderHandler.checkPaid(unixOrderDto);
//        //订单支付
//        PayRequest payRequest = new PayRequest();
//        BeanUtil.copyProperties(orderPayDto, payRequest);
//
//        //除了余额支付是直接支付写更新流水状态 企业 三方支付只返回预下单表示，不改支付流水状态为已支付状态
//       // return payClient.getPayApi(orderPayDto.getPayType()).pay(payRequest);
//        return null;
//    }
//
//    public Boolean closeOrder(UnifiedXsnOrderDto unifiedXsnOrderDto) {
//        Integer orderType = unifiedXsnOrderDto.getOrderType();
//        // 获取订单处理器
//        AbstractOrder orderHandler = unifiedOrderService.getOrderHandler(orderType);
//        // 关单
//        return orderHandler.closeOrder(unifiedXsnOrderDto);
//    }
//
//    public DataResult<PayResponse> payQuery(OrderPayDto orderPayDto) {
//        PayRequest payRequest = new PayRequest();
//        BeanUtil.copyProperties(orderPayDto, payRequest);
//        DataResult<PayResponse> responseDataResult = null;
//                //payClient.getPayApi(orderPayDto.getPayType()).payQuery(payRequest);
//
//        if (responseDataResult.isSuccess() && Objects.equals(responseDataResult.getData().getPayStatus(), PayRequest.SUCCESS_PAY)) {
//            //todo  主动权益下发
//        }
//        return responseDataResult;
//    }
//
//    public DataResult<RefundResponse> refund(OrderPayDto orderPayDto) {
//        Integer orderType = orderPayDto.getOrderType();
//        AbstractOrder orderHandler = unifiedOrderService.getOrderHandler(orderType);
//        // todo 校验该笔退款没有
//        RefundRequest payRequest = new RefundRequest();
//        DataResult<RefundResponse> refund =null;
//                //payClient.getPayApi(orderPayDto.getPayType()).refund(payRequest);
//        //todo 写入退款流水
//        return refund;
//    }
//
//    public DataResult<RefundResponse> refundQuery(OrderPayDto orderPayDto) {
//        // todo 查询退款流水记录存不存在
//        RefundRequest payRequest = new RefundRequest();
//        DataResult<RefundResponse> refund = null;
//                //payClient.getPayApi(orderPayDto.getPayType()).refundQuery(payRequest);
//        //todo 写入退款流水 修改订单状态为已退款
//        return refund;
//    }
}
